package dr.incomeapp.controller;

import java.util.Observable;
import java.util.Observer;

import android.app.Activity;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.DatePicker;
import android.widget.ProgressBar;

import com.google.ads.AdRequest;
import com.google.ads.AdView;

import dr.incomeapp.Application;
import dr.incomeapp.R;
import dr.incomeapp.Debug.MyDebug;

public class MyController extends Activity implements OnClickListener, 
		Observer, OnItemClickListener, OnDateSetListener {

	protected MyDebug myDebug;

	// protected static final String MY_BANNER_UNIT_ID = "a15026b311d7f7e";

	protected AdView adView = null;

	protected ProgressDialog progressDialog = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		progressDialog = new ProgressDialog(this);
		myDebug = new MyDebug(this.getClass().getSimpleName());
	}

	protected void init() {
		/*
		setLoading(false);

		adView = (AdView) findViewById(R.id.adView);

		if (adView == null) {
			return;
		}

		AdRequest re = Application.GetInstance().getAdRequest();
		re.setTesting(true);

		adView.loadAd(re);
		*/
	}
	
	public void clear(){
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu, menu);
		return true;
	}

	protected void setLoading(boolean visible) {
		ProgressBar pb = (ProgressBar) findViewById(R.id.pb0Progress);
		if (visible) {
			pb.setVisibility(ProgressBar.VISIBLE);
		} else {
			pb.setVisibility(ProgressBar.INVISIBLE);
		}
	}

	public void showProgressDialog() {
		
		Resources res = getResources();

		progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		progressDialog.setMessage(res.getString((R.string.loading)));
		progressDialog.setCancelable(false);

		progressDialog.show();
	}

	public void showFullLoading() {
		showProgressDialog();
		setLoading(true);
	}

	public void hideFullLoading() {
		hideProgressDialog();
		setLoading(false);
	}

	public void hideProgressDialog() {
		if (progressDialog != null && progressDialog.isShowing()) {

			progressDialog.hide();
		}
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.itDebug:
			Intent myIntent = new Intent(this, DebugController.class);
			startActivity(myIntent);
		}
		return true;
	}

	public void onClick(View v) {

	}

	public void update(Observable observable, Object data) {

		hideFullLoading();

	}

	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub

	}

	public void onDateSet(DatePicker view, int year, int monthOfYear,
			int dayOfMonth) {
		// TODO Auto-generated method stub
		
	}

}
